package com.wl.eb.controller;

import com.wl.eb.module.EbNews;
import com.wl.eb.service.NewsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
@RequestMapping("/news")
public class NewsController {
    @Resource
    private NewsService newsService;

    @RequestMapping("/details")
    public String details(Model model,int newsId) throws Exception{
        //1.调用service根据newsId查询新闻
        EbNews newsDetails = newsService.details(newsId);
        if (newsDetails==null){
            throw new RuntimeException("该新闻不存在");
        }
        //2.将详情数据绑定到model
        model.addAttribute("details",newsDetails);
        //3.返回view
        return "news-view";
    }

}
